package com.chisheng.service.impl;

import com.chisheng.mapper.SecureExamMapper;
import com.chisheng.pojo.SecureSolution;
import com.chisheng.pojo.SecureProblem;
import com.chisheng.service.SecureExamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class SecureExamServiceImpl implements SecureExamService {

    /**
     * SecureExamMapper
     */
    private SecureExamMapper sem;

    @Override
    public List<Integer> accurateSearch(String subject) {
        try {
            SecureProblem question = sem.findByTitle(subject);
            return question.getSolution()
                    .stream()
                    .map(SecureSolution::getOptionIndex)
                    .collect(Collectors.toList());
        } catch (Exception e) {
            // SecurePassword::getPassword 异常表示无结果
            return List.of();
        }
    }

    @Autowired
    public void setSem(SecureExamMapper sem) {
        this.sem = sem;
    }

}
